// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/questionnaire/api/IbQuestionnaireApi'

import ListClass from '@api/questionnaire/model/QuestionnaireAnswerReq'

import UTIL from '@admin/views/Operation/detail/DetailQuestionnaire/store/answer/UTIL'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return param.questionnaireId
  },
  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param)
    const { comQuery = {}, dtos = [] } = await CORE.grpc(TIP, CLIENT, 'questionnaireAnswer', DTO)
    return [comQuery.totalCount || dtos.length, dtos]
  },
  transList(arr, { rootState: { one: { questionList } } }) {
    arr.forEach((item) => UTIL.setAnswer(item, questionList, item.dtos))
    return arr
  },
}
